package cn.itlaobing.eshop.dao;/**
 * Created by 1223 on 2017/11/15.
 */


import cn.itlaobing.eshop.entity.Users;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * 类名：
 * 描述：
 * 作者：陈志凯
 * 时间：2017/11/15
 */
public class UsersDao extends BaseDao{
    /**
     * 登录
     * */
    public Users findByAccount(String userAccount,String userPassword) throws SQLException {
        QueryRunner runner=new QueryRunner(getDataSource());
        String sql="SELECT * FROM users WHERE userAccount=? AND userPassword=? ";
        BeanHandler<Users> beanHandler=new BeanHandler<Users>(Users.class);
        return runner.query(sql,beanHandler,userAccount,userPassword);
    }
    /**
     * 注册
     * */
    public int addAccount(String userAccount,String userPassword) throws SQLException{
        QueryRunner runner=new QueryRunner(getDataSource());
        String sql="insert into users (userAccount,userPassword) values(?,?)";
        return runner.update(sql,userAccount,userPassword);
    }


}
